/**
 * 
 */
package com.handinfo.uimenu.window;

import java.io.DataInputStream;
import java.io.IOException;

import javax.microedition.lcdui.Graphics;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.GameManager;
import com.handinfo.engine.net.GameProtocol;
import com.handinfo.game.AbstractGameActor;
import com.handinfo.game.ActorItem;
import com.handinfo.game.ActorRole;
import com.handinfo.game.GameScene;
import com.handinfo.game.MenuFunction;
import com.handinfo.game.RoleCombatSkill;
import com.handinfo.uimenu.UIAbstractWindow;
import com.handinfo.uimenu.UIListener;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UIMessageBox;
import com.handinfo.uimenu.UIPopmenu;
import com.handinfo.uimenu.UITools;
import com.handinfo.uimenu.UIWindowFactory;
import com.handinfo.util.ArrayList;
import com.handinfo.util.Tools;
import com.test.touch.GameTouchManager;

/**
 * @author venizeng
 * 
 */
public class UISetShortCut extends UIAbstractWindow
{
	private static final int STATE_SET = 1;// 普通入口
	private static final int STATE_TEACH = 2;// 教學
	//
	private final int GROUP_SET_SHORTCUT = 1;
	private final int GROUP_SET_BAG = 2;
	//
	private final int NUM_SET_SHORTCUT_ROW = 1;// 显示多少行
	private final int NUM_SET_SHORTCUT_COL = 9;// 显示多少列
	private final int NUM_SET_BAG_ROW = 6;// 背包格子顯示多少行
	private final int NUM_SET_BAG_COL = 6;
	//
	private final int INDEX_SET_BAR_FIRST = 0;
	private final int INDEX_SET_BAG_FIRST = NUM_SET_SHORTCUT_ROW * NUM_SET_SHORTCUT_COL;
	//
	private Object[][] m_set_shortcutItems;// 快捷栏对象
	private Object[] m_set_bagItems;// 背包栏对象
	private long[][][] m_set_tempShortcut;// 如数据发生修改，则将此数据替换玩家快捷栏
	//
	private boolean m_set_isOperLocked;// 当发送快捷栏生效时，行为锁定
	private int m_set_index_switch;// 快捷栏索引
	private int m_set_index_shortcut;// 选中的快捷栏索引
	private int m_set_bag_top;
	private int m_set_plan;
	private int m_set_relY_label;

	private int SIZE_SET_SKILL;
	private int SIZE_SET_FUN;
	private int SIZE_SET_ACTORITEM;

	private final int IW_CONTENT = UIManager.getColorsSubcoatBorder().length;
	private final int W_BG = UITools.W_BG;
	private final int H_BG = UITools.H_BG;
	// private final int IW_SET_SHORTCUT_CONTENT = 4;
	// private final int W_SET_SHORTCUT_CONTENT = W_BG - (IW_SET_SHORTCUT_CONTENT << 1);
	private final int H_SET_SHORTCUT_CONTENT = UITools.H_BAG + (UITools.IW_RECT_CONTENT << 1);
	private final int IW_SET_SHORTCUT = 2;
	private final int IH_SET_SHORTCUT = 5;
	private final int RW_SET_SHORTCUT = UITools.W_BAG + IW_SET_SHORTCUT;
	private final int RH_SET_SHORTCUT = UITools.H_BAG + IH_SET_SHORTCUT;
	private final int IW_SET_BAG = 3;
	private final int IH_SET_BAG = 5;
	private final int RW_SET_BAG = UITools.W_BAG + IW_SET_BAG;
	private final int RH_SET_BAG = UITools.H_BAG + IH_SET_BAG;
	private final int H_SET_BAG = ((RH_SET_BAG * NUM_SET_BAG_ROW) - IH_SET_SHORTCUT) + (IW_CONTENT << 1);
	private final int W_SET_BAG = UITools.W_RECT_DRAG;
	// private final int W_SET_DESCRIBE = UITools.W_RECT;
	// private final int H_SET_DESCRIBE = ((AbstractGameScreen.FONT_H + UITools.IH_RECT_CONTENT) << 1);
	private final int W_SET_LABEL = UITools.W_BUTTON_MIDDLE;// 标签的大小
	private final int H_SET_LABEL = UITools.H_LABEL;
	private final int H_SET_MID = 0;// 中间的间隙

	//
	private int H_SET_SKILL;// 技能栏的高度]
	private int H_SET_ITEM = 0;
	//
	// private final int X_SET_SHORTCUT_CONTENT = IW_SET_SHORTCUT_CONTENT;
	private final int Y_SET_SHORTCUT_CONTENT = UITools.INITY_CONTENT;
	private final int X_SET_SHORTCUT = ((W_BG - (RW_SET_SHORTCUT * NUM_SET_SHORTCUT_COL - IW_SET_SHORTCUT)) >> 1);
	private final int Y_SET_SHORTCUT = Y_SET_SHORTCUT_CONTENT + UITools.IH_RECT_CONTENT;
	private final int X_SET_BAG_RECT = UITools.IW_WIN;
	private final int Y_SET_BAG_RECT = Y_SET_SHORTCUT_CONTENT + H_SET_SHORTCUT_CONTENT + UITools.IH_RECT_CONTENT;
	private final int X_SET_LABEL = X_SET_BAG_RECT + IW_CONTENT;
	private final int Y_SET_LABEL = Y_SET_BAG_RECT + IW_CONTENT;
	private final int X_SET_BAG = X_SET_LABEL + W_SET_LABEL
			+ ((W_SET_BAG - W_SET_LABEL - (IW_CONTENT << 1) - (NUM_SET_BAG_COL * RW_SET_BAG - IW_SET_BAG)) >> 1);
	private final int Y_SET_BAG = Y_SET_LABEL;
	private final int X_SET_DESCRIBE = UITools.INITX_CONTENT;
	private final int Y_SET_DESCRIBE = Y_SET_BAG + H_SET_BAG;
	//
	private int m_set_x_shortcut_fos;
	private int m_set_x_bag_fos;
	private int m_set_y_bag_fos;

	//
	private final String TITLE = "快捷栏设置";

	public UISetShortCut(int id)
	{
		super(id);
		setBounds(UITools.X_BG, UITools.Y_BG, W_BG, H_BG);
	}

	/**
	 * 进入教学 2012-3-9 下午05:09:18 venizeng
	 */
	public static final void gotoTeachSetMenu()
	{
		openMenu(STATE_TEACH);
	}

	private static final void gotoTeachSetShortcut()
	{
		UISetShortCut shortCut2 = (UISetShortCut) UIWindowFactory.createWindow(UIWindowFactory.WINDOW_SET_SHORTCUT);
		shortCut2.init();
		shortCut2.setWindowStatus(STATE_TEACH);
		shortCut2.setWindowIndex(shortCut2.INDEX_SET_BAR_FIRST + UIMain.POS_SET_SKILL);//设置位置，焦点需要此行代码设置
//		shortCut2.setWindowIndex(shortCut2.INDEX_SET_BAG_FIRST +index);
		UIManager.getInstance().addWindow(shortCut2);
	}

	public void recvMessage(int orderId, DataInputStream dis) throws IOException
	{
		switch (orderId) {
			case GameProtocol.CS_SET_SHORTCUT:
				recvSetShortcutConfig(dis);
				m_set_isOperLocked = false;
				break;
		}
	}

	private void recvSetShortcutConfig(DataInputStream dis) throws IOException
	{
		short state = dis.readShort();
		String info = dis.readUTF();
		if (state == 0) {
			if (!info.equals("")) {
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, info);// 正确不提示
			}
			return;
		}
		// long[][][] shortcut = GameManager.getInstance().m_role.m_shortcut;
		// for (int i = 0; i < m_set_temp.length; i++) {
		// for (int j = 0; j < m_set_temp[i].length; j++) {
		// if (m_set_temp[i][j] == null) {
		// shortcut[i][j][0] = AbstractGameActor.ACTION_TYPE_NONE;
		// shortcut[i][j][1] = -1;
		// continue;
		// }
		// if (m_set_temp[i][j] instanceof RoleCombatSkill) {
		// shortcut[i][j][0] = AbstractGameActor.ACTION_TYPE_SKILL;
		// shortcut[i][j][1] = ((RoleCombatSkill) m_set_temp[i][j]).m_id;
		// }
		// else if (m_set_temp[i][j] instanceof ActorItem) {
		// shortcut[i][j][0] = AbstractGameActor.ACTION_TYPE_ITEM;
		// shortcut[i][j][1] = ActorItem.getActorItemKeyId(((ActorItem) m_set_temp[i][j]));
		// }
		// else if (m_set_temp[i][j] instanceof Function) {
		// shortcut[i][j][0] = AbstractGameActor.ACTION_TYPE_FUNCTION;
		// shortcut[i][j][1] = ((Integer) m_set_temp[i][j]).intValue();
		// }
		// else {
		// shortcut[i][j][0] = AbstractGameActor.ACTION_TYPE_NONE;
		// shortcut[i][j][1] = -1;
		// }
		// }
		// }
		GameManager.getInstance().m_role.m_shortcut = m_set_tempShortcut;
		close();
	}

	//

	/**
	 * 初始化当前数据 2012-3-5 上午09:44:49 venizeng
	 */
	private void init()
	{
		m_set_tempShortcut = setInitShortcut();
		//
		final ActorRole role = GameManager.getInstance().m_role;
		m_set_shortcutItems = new Object[m_set_tempShortcut.length][m_set_tempShortcut[0].length];
		for (int i = 0, length1 = m_set_tempShortcut.length; i < length1; i++) {
			for (int j = 0, length2 = m_set_tempShortcut[i].length; j < length2; j++) {
				m_set_shortcutItems[i][j] = role.getShortcutData(i, j);
			}
		}
		//
		RoleCombatSkill[] skills = GameManager.getInstance().m_role.m_roleCombatSkill[0];
		ActorItem[] items = getActorItemsFitForShortcut();
		MenuFunction[] menus = MenuFunction.cretaeMenus();
		int SIZE_SET_SKILL_ROW = (skills.length + NUM_SET_BAG_COL - 1) / NUM_SET_BAG_COL;
		int SIZE_SET_ACTORITEM_ROW = items == null ? 0 : (items.length + NUM_SET_BAG_COL - 1) / NUM_SET_BAG_COL;
		int SIZE_SET_FUN_ROW = (menus.length + NUM_SET_BAG_COL - 1) / NUM_SET_BAG_COL;
		SIZE_SET_SKILL = NUM_SET_BAG_COL * SIZE_SET_SKILL_ROW;
		SIZE_SET_FUN = NUM_SET_BAG_COL * SIZE_SET_FUN_ROW;
		SIZE_SET_ACTORITEM = SIZE_SET_ACTORITEM_ROW * NUM_SET_BAG_COL;

		m_set_bagItems = new Object[SIZE_SET_SKILL + SIZE_SET_ACTORITEM + SIZE_SET_FUN];// 能设置进去的道具，需要規則獲得技能與功能對象
		//设置技能
		int index = 0;
		if (skills != null) {
			for (int i = 0, maxSize = skills.length; i < SIZE_SET_SKILL; i++) {
				if (i >= maxSize) {
					break;
				}
				if (!RoleCombatSkill.isFitforSet(skills[i])) {
					continue;
				}
				m_set_bagItems[index] = skills[i];
				index++;
			}
		}
		index = SIZE_SET_SKILL;
		if (items != null) {
			for (int i = 0; i < items.length; i++) {
				m_set_bagItems[index] = items[i];
				index++;
			}
		}

		index = SIZE_SET_SKILL + SIZE_SET_ACTORITEM;
		for (int i = 0; i < menus.length; i++) {
			m_set_bagItems[index + i] = menus[i];
		}
		H_SET_SKILL = SIZE_SET_SKILL_ROW * RH_SET_BAG;
		H_SET_ITEM = SIZE_SET_ACTORITEM_ROW * RH_SET_BAG;
		//
	}

	private ActorItem[] getActorItemsFitForShortcut()
	{
		ActorItem[] items = GameManager.getInstance().m_role.m_bag_goods;
		if (items == null) {
			return null ;
		}
		ArrayList list = new ArrayList(10, 10);
		for (int i = 0; i < items.length; i++) {
			if (items[i] == null) {
				continue;
			}
			if (items[i].isFitforShortcut()) {
				list.addElement(items[i]);
			}
		}
		int size = list.size();
		if (size == 0) {
			return null;
		}
		ActorItem[] result = new ActorItem[size];
		for (int i = 0; i < result.length; i++) {
			result[i] = (ActorItem) list.elementAt(i);
		}
		return result;
	}

	/**
	 * 当前操作是否发生改变 2012-3-2 下午01:59:36 venizeng
	 * @return
	 */
	private boolean isShortcutChanged()
	{
		final long[][][] shortcut = GameManager.getInstance().m_role.m_shortcut;
		for (int i = 0, length1 = shortcut.length; i < length1; i++) {
			for (int j = 0, length2 = shortcut[i].length; j < length2; j++) {
				if (m_set_tempShortcut[i][j][0] != shortcut[i][j][0]) {
					return true;
				}
				if (m_set_tempShortcut[i][j][1] != shortcut[i][j][1]) {
					return true;
				}
			}
		}
		return false;
	}

	/**
	 * 初始化快捷栏 重设快捷栏 2012-3-2 下午04:09:41 venizeng
	 * @return
	 */
	private long[][][] setInitShortcut()
	{
		final long[][][] shortcut = GameManager.getInstance().m_role.m_shortcut;
		long[][][] temp = new long[shortcut.length][shortcut[0].length][shortcut[0][0].length];
		for (int i = 0, length1 = shortcut.length; i < length1; i++) {
			for (int j = 0, length2 = shortcut[i].length; j < length2; j++) {
				temp[i][j][0] = shortcut[i][j][0];
				temp[i][j][1] = shortcut[i][j][1];
			}
		}
		return temp;
	}

	public static final void test()
	{
		UISetShortCut shortCut2 = new UISetShortCut(-1);
		shortCut2.init();
		shortCut2.setWindowStatus(STATE_SET);
		shortCut2.setWindowIndex(0);
		UIManager.getInstance().addWindow(shortCut2);
	}

	public static void openSetMenu()
	{
		openMenu(UISetShortCut.STATE_SET);
	}

	private static void openMenu(final int type)
	{
		final UIPopmenu popmenu = (UIPopmenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_POPMENU);
		final String SET_SHORTCUT = "快捷栏设置";
		popmenu.setPopmenus(new String[] { "系统设置", SET_SHORTCUT, "连招设置" });
		if (type == STATE_TEACH) {
			popmenu.setStop();
			popmenu.setStopMenu(1);
		}
		popmenu.addListener(new UIListener() {
			public void actionPerformed()
			{
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					if( GameManager.getInstance().m_role.m_lv < 1){
						GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "达到6级以上才能使用此功能！");
						return;
					}
					int index = popmenu.getCurrentIndex();
					UIManager.getInstance().removeWindow(popmenu);
					switch (index) {
						case 0:
							UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_SET_SYSTEM);
							// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "暂不开放");
							break;
						case 1:
							{
							UISetShortCut shortCut2 = (UISetShortCut) UIWindowFactory
									.createWindow(UIWindowFactory.WINDOW_SET_SHORTCUT);
//							if (type == STATE_TEACH) {
//								gotoTeachSetShortcut();
//							}
//							else//老子要去掉教学。 
							{
								shortCut2.init();
								shortCut2.setWindowStatus(STATE_SET);
								shortCut2.setWindowIndex(0);
								UIManager.getInstance().addWindow(shortCut2);
							}
						}
							break;
						case 2:
				//							GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "暂时不开放");
				UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_SET_MARCOS);
				break;
		}
	}
	else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
		if (type == STATE_TEACH) {
			return;
		}
		UIManager.getInstance().removeWindow(popmenu);
	}
}
		});
	}

	protected int countGroupId(int mIndex)
	{
		switch (m_state) {
			case STATE_SET:
			case STATE_TEACH:
				if (mIndex < INDEX_SET_BAG_FIRST) {
					return GROUP_SET_SHORTCUT;
				}
				return GROUP_SET_BAG;
			default:
				break;
		}
		return 0;
	}

	protected int countGroupIndex(int mGroupId, int mIndex)
	{
		switch (m_state) {
			case STATE_SET:
			case STATE_TEACH:
				switch (mGroupId) {
					case GROUP_SET_SHORTCUT:
						return mIndex;
					case GROUP_SET_BAG:
					default:
						return mIndex - INDEX_SET_BAG_FIRST;
				}
			default:
				break;
		}
		return 0;
	}

	/*************************/
	// KeyLogic
	/*************************/
	protected void keyLogic()
	{
		switch (m_state) {
			case STATE_SET:
				keyLogicOnNormal();
				break;
			case STATE_TEACH:
				keyLogicOnTeach();
				break;
		}
	}

	private int m_order_teach_shortcut;
	private int m_index_teach_set_shortcut;

	private void keyLogicOnTeach()
	{
		switch (m_groupId) {
			case GROUP_SET_BAG:
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {
					clickSetBagItem();
				}
				break;
			case GROUP_SET_SHORTCUT:
				switch (m_order_teach_shortcut) {
					case 0:
						int index = -1;//獲得某道具在背包中的位置
						Object[] datas = m_set_bagItems;
						for (int i = 0; i < m_set_bagItems.length; i++) {
							if (datas[i] == null) {
								continue;
							}
							if (datas[i] instanceof RoleCombatSkill) {
								RoleCombatSkill skill = (RoleCombatSkill) datas[i];
								if (skill.m_id == UIMain.ID_SET_SKILL) {
									index = i;
									break;
								}
							}
							else if (datas[i] instanceof MenuFunction) {
								MenuFunction function = (MenuFunction) datas[i];
								if (function.m_id == UIMain.ID_SET_SKILL) {
									index = i;
									break;
								}
							}
						}
						if (index == -1) {
							GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "无此技能");
							close();
							return;
						}
						m_index_teach_set_shortcut = index;
						m_order_teach_shortcut++;
						break;
					case 1:
						if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
							setWindowIndex(m_index_teach_set_shortcut + INDEX_SET_BAG_FIRST);
							m_order_teach_shortcut++;//下一级
						}
						break;

					default:
						if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
							keySetLeftSoft();
						}
						break;
				}
				break;
		}
	}

	private void keyLogicOnNormal()
	{
		if (m_set_isOperLocked) {
			return;
		}
		if (AbstractGameScreen.haveKeyPressed(KEY_DETAIL)) {
			reviewSetDetail();
		}
		else if (AbstractGameScreen.haveKeyPressed(KEY_DELETE)) {// 删除当前
			deleteSetShortcut();
		}
		else if (AbstractGameScreen.haveKeyPressed(KEY_SWITCH)) {// 快捷栏切换
			switchSetShortcut();
		}
		else {
			switch (m_groupId) {
				case GROUP_SET_SHORTCUT:
					if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
						keySetLeftSoft();
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
						keySetRightSoft();
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
						if (m_index < NUM_SET_SHORTCUT_COL) {
							return;
						}
						setWindowIndex(m_index - NUM_SET_SHORTCUT_COL);
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
						if (m_index >= (NUM_SET_SHORTCUT_ROW - 1) * NUM_SET_SHORTCUT_COL) {
							return;
						}
						else {
							setWindowIndex(m_index + NUM_SET_SHORTCUT_COL);
						}
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
						if (m_groupIndex <= 0) {
							setWindowIndex(INDEX_SET_BAR_FIRST + NUM_SET_SHORTCUT_COL - 2);
						}
						else {
							setWindowIndex(m_index - 1);
						}
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
						if (m_groupIndex >= NUM_SET_SHORTCUT_COL - 2) {
							setWindowIndex(INDEX_SET_BAR_FIRST);
						}
						else {
							setWindowIndex(m_index + 1);
						}
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
							|| AbstractGameScreen.haveKeyPressed(KEY_CONFIG)) {
						clickSetShortcutItem();
					}
					break;
				case GROUP_SET_BAG:
				default:
					if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
						if (m_groupIndex < NUM_SET_BAG_COL) {// 显示最上
							if (m_set_bag_top != 0) {
								changeSetBagTop(m_set_bag_top - NUM_SET_BAG_COL);
							}
						}
						else {
							setWindowIndex(m_index - NUM_SET_BAG_COL);
						}
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
						if (m_groupIndex < (NUM_SET_BAG_ROW - 1) * NUM_SET_BAG_COL) {
							setWindowIndex(m_index + NUM_SET_BAG_COL);
						}
						else {// 显示最下
							if (m_set_bagItems == null) {
								return;
							}
							int realBagItemIndex = m_groupIndex + m_set_bag_top;
							if (realBagItemIndex + NUM_SET_BAG_COL < m_set_bagItems.length) {
								changeSetBagTop(m_set_bag_top + NUM_SET_BAG_COL);
							}
							else {
								int num = NUM_SET_BAG_COL - m_groupIndex % NUM_SET_BAG_COL;// 还剩多少个格子
								if (m_set_bagItems.length - realBagItemIndex > num) {// 数据有下一行
									changeSetBagTop(m_set_bag_top + NUM_SET_BAG_COL);// 数据上移一行
									setWindowIndex(INDEX_SET_BAG_FIRST + (NUM_SET_BAG_ROW - 1)
											* NUM_SET_BAG_COL + (m_set_bagItems.length - 1) % NUM_SET_BAG_COL);// 焦点设置到最后一个格子上
								}
							}
						}
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
						if (m_groupIndex % NUM_SET_BAG_COL == 0) {
							setWindowIndex(m_index + NUM_SET_BAG_COL - 1);
						}
						else {
							setWindowIndex(m_index - 1);
						}
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
						if (m_groupIndex % NUM_SET_BAG_COL == NUM_SET_BAG_COL - 1) {
							setWindowIndex(m_index - (NUM_SET_BAG_COL - 1));
						}
						else {
							setWindowIndex(m_index + 1);
						}
						// if (m_groupIndex < NUM_SET_BAG_ROW * NUM_SET_BAG_COL - 1) {
						// setWindowIndex(m_index + 1);
						// }
						// else {// 显示最下
						// if (m_set_bagItems == null) {
						// return;
						// }
						// int realBagItemIndex = m_groupIndex + m_set_bag_top;
						// if (realBagItemIndex + 1 < m_set_bagItems.length) {
						// changeSetBagTop(m_set_bag_top + NUM_SET_BAG_COL);
						// setWindowIndex(INDEX_SET_BAG_FIRST + (NUM_SET_BAG_ROW - 1) * NUM_SET_BAG_COL);
						// }
						// }
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
						keySetLeftSoft();
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
							|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {
						clickSetBagItem();
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
						keySetRightSoft();
					}
					break;
			}
		}
	}

	/**
	 * 2012-3-5 下午02:40:32 venizeng
	 */
	private void switchSetShortcut()
	{
		if (m_set_index_switch == 0) {
			m_set_index_switch = GameManager.getInstance().m_role.m_shortcut.length - 1;
		}
		else {
			m_set_index_switch--;
		}
	}

	private void keySetLeftSoft()
	{
		final UIMessageBox messageBox = (UIMessageBox) UIManager.getInstance().createWindow(
				UIWindowFactory.WINDOW_MESSAGEBOX);
		final boolean isShortcutChanged = isShortcutChanged();
		String temp = isShortcutChanged ? "快捷栏已经发生修改，是否确认设置" : "快捷栏未发生修改，是否退出";
		messageBox.setMessage(temp);
		messageBox.addListener(new UIListener() {

			public void actionPerformed()
			{
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT) || AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					UIManager.getInstance().removeWindow(messageBox);
					if (isShortcutChanged) {
						GameManager.getInstance().m_game_message.sendSetShortCut(m_set_tempShortcut);
						m_set_isOperLocked = true;
					}
					else {
						close();
					}
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
					if (m_state == STATE_TEACH) {
						return;
					}
					UIManager.getInstance().removeWindow(messageBox);
				}
			}
		});
	}

	private void keySetRightSoft()
	{
//		switch (m_state) {
//			case STATE_SET:
//				switch (m_groupId) {
//					case GROUP_SET_BAG:
//						setWindowIndex(m_set_index_shortcut);// 返回到快捷栏
//						return;
//				}
//				break;
//		}
		final UIMessageBox messageBox = (UIMessageBox) UIManager.getInstance().createWindow(
				UIWindowFactory.WINDOW_MESSAGEBOX);
		final boolean isShortcutChanged = isShortcutChanged();
		String temp = isShortcutChanged ? "快捷栏已经发生修改，是否退出设置" : "快捷栏未发生修改，是否退出设置";
		messageBox.setMessage(temp);
		messageBox.addListener(new UIListener() {

			public void actionPerformed()
			{
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
					UIManager.getInstance().removeWindow(messageBox);
					close();
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
					UIManager.getInstance().removeWindow(messageBox);
				}
			}
		});
	}

	private void reviewSetDetail()
	{
		switch (m_state) {
			case STATE_SET:
				switch (m_groupId) {
					case GROUP_SET_SHORTCUT:
						reviewSetDetail(m_set_shortcutItems[m_set_index_switch][m_set_index_shortcut]);
						break;
					case GROUP_SET_BAG:
					default:
						reviewSetDetail(m_set_bagItems[m_groupIndex]);
						break;
				}
				break;
			default:
				break;
		}
	}

	private void reviewSetDetail(Object object)
	{
		if (object == null) {
			return;
		}
		if (object instanceof RoleCombatSkill) {
			RoleCombatSkill skill = (RoleCombatSkill) object;
			GameManager.getInstance().m_game_message.sendSkillDetail(skill.m_id);
		}
	}

	/**
	 * 2012-3-5 上午11:20:11 venizeng
	 */
	private void deleteSetShortcut()
	{
		switch (m_state) {
			case STATE_SET:
				switch (m_groupId) {
					case GROUP_SET_SHORTCUT:
						changeSetShortcut(null);
						break;
				}
				break;
			default:
				break;
		}
	}

	/**
	 * 点击道具格子，设置快捷栏 2012-3-2 下午04:44:51 venizeng
	 */
	private void clickSetBagItem()
	{
		int index = m_set_bag_top + m_groupIndex;
		if (index >= m_set_bagItems.length) {
			changeSetShortcut(null);
		}
		else {
			if (m_set_bagItems[index] != null) {
				changeSetShortcut(m_set_bagItems[index]);
			}
		}
		setWindowIndex(m_set_index_shortcut);
	}

	/**
	 * 点击道具格子，设置快捷栏 2012-3-2 下午04:44:51 venizeng
	 */
	private void clickSetShortcutItem()
	{
		setWindowIndex(INDEX_SET_BAG_FIRST);
	}

	private void changeSetShortcut(Object object)
	{
		if (m_set_shortcutItems[m_set_index_switch][m_set_index_shortcut] == object) {
			return;
		}
		m_set_shortcutItems[m_set_index_switch][m_set_index_shortcut] = object;
		if (object == null) {
			m_set_tempShortcut[m_set_index_switch][m_set_index_shortcut][0] = AbstractGameActor.ACTION_TYPE_NONE;
			m_set_tempShortcut[m_set_index_switch][m_set_index_shortcut][1] = 0;
		}
		else {
			if (object instanceof RoleCombatSkill) {
				m_set_tempShortcut[m_set_index_switch][m_set_index_shortcut][0] = AbstractGameActor.ACTION_TYPE_SKILL;
				m_set_tempShortcut[m_set_index_switch][m_set_index_shortcut][1] = ((RoleCombatSkill) object).m_id;
			}
			else if (object instanceof MenuFunction) {
				m_set_tempShortcut[m_set_index_switch][m_set_index_shortcut][0] = AbstractGameActor.ACTION_TYPE_FUNCTION;
				m_set_tempShortcut[m_set_index_switch][m_set_index_shortcut][1] = ((MenuFunction) object).getId();
			}else if (object instanceof ActorItem) {
				m_set_tempShortcut[m_set_index_switch][m_set_index_shortcut][0] = AbstractGameActor.ACTION_TYPE_ITEM;
				m_set_tempShortcut[m_set_index_switch][m_set_index_shortcut][1] = ((ActorItem) object).m_guid;
			}
		}
	}

	private void changeSetBagTop(int set_bag_top)
	{
		m_set_bag_top = set_bag_top;
		changeSetLabelRelY();
		actionOnIndexChanged();
	}

	private void changeSetLabelRelY()
	{
		m_set_relY_label = -RH_SET_BAG * (m_set_bag_top / NUM_SET_BAG_COL);
	}

	protected void actionOnIndexChanged()
	{
		super.actionOnIndexChanged();
		switch (m_state) {
			case STATE_SET:
			case STATE_TEACH:
				switch (m_groupId) {
					case GROUP_SET_SHORTCUT:
						m_set_index_shortcut = m_groupIndex;
						m_set_x_shortcut_fos = m_set_index_shortcut * RW_SET_SHORTCUT;
						//
						m_set_plan = 0;
						break;
					case GROUP_SET_BAG:
					default:
						m_set_x_bag_fos = (m_groupIndex % NUM_SET_BAG_COL) * RW_SET_BAG;
						m_set_y_bag_fos = (m_groupIndex / NUM_SET_BAG_COL) * RH_SET_BAG;
						if (m_groupIndex + m_set_bag_top >= SIZE_SET_SKILL) {// 功能
							m_set_y_bag_fos += H_SET_MID;
						}
						//
						if (m_set_bagItems == null) {
							return;
						}
						int realbagIndex = m_groupIndex + m_set_bag_top;
						if (realbagIndex >= m_set_bagItems.length) {
							changeSetShortcut(null);
						}
						else {
							changeSetShortcut(m_set_bagItems[realbagIndex]);
						}
						//
						int maxSize = 0;
						if (m_set_bagItems == null) {
							maxSize = NUM_SET_BAG_ROW;
						}
						else {
							maxSize = (m_set_bagItems.length + NUM_SET_BAG_COL - 1) / NUM_SET_BAG_COL;
						}
						maxSize = maxSize < NUM_SET_BAG_ROW ? NUM_SET_BAG_ROW : maxSize;
						int rowIndex = ((m_set_bag_top + m_groupIndex) / NUM_SET_BAG_COL) + 1;
						if (rowIndex == 1) {
							m_set_plan = 0;
						}
						else if (rowIndex == maxSize) {
							m_set_plan = 100;
						}
						else {
							m_set_plan = (rowIndex * 100) / (maxSize);
						}
						changeSetLabelRelY();
						//
						break;
				}
				break;

			default:
				break;
		}
	}

	protected void paintContent(Graphics g)
	{
		UITools.paintBackGround(g, m_x, m_y, m_w, m_h, TITLE);
		paintSetShortcut(g);
		paintBagRect(g);
		paintSetDrag(g);
		paintSetDescribe(g);
		paintSetFocus(g);
		paintSetSkillDescribe(g);
		paintYindao(g);
	}

	private int getYindaoX()
	{
		int tempX = 0;
		switch (m_groupId) {
			case GROUP_SET_SHORTCUT:
				tempX = X_SET_SHORTCUT;
				tempX += (m_groupIndex % NUM_SET_SHORTCUT_COL) * RW_SET_SHORTCUT;
				break;
			case GROUP_SET_BAG:
				tempX = X_SET_BAG;
				tempX += (m_groupIndex % NUM_SET_BAG_COL) * RW_SET_SHORTCUT;
				break;
		}
		return tempX;
	}

	private int getYindaoY()
	{
		int tempY = m_y;
		switch (m_groupId) {
			case GROUP_SET_SHORTCUT:
				tempY = Y_SET_SHORTCUT;
				tempY += (m_groupIndex / NUM_SET_SHORTCUT_COL) * RH_SET_SHORTCUT;
				break;
			case GROUP_SET_BAG:
				tempY = Y_SET_BAG;
				tempY += (m_groupIndex / NUM_SET_BAG_COL) * RH_SET_SHORTCUT;
				break;
		}
		return tempY;
	}

	private void paintYindao(Graphics g)
	{
		switch (m_state) {
			case STATE_TEACH:
				int W = 80;
				switch (m_groupId) {
					case GROUP_SET_SHORTCUT:
						String string = m_order_teach_shortcut == 1 ? "单击选择快捷栏位置" : "点击确认键，确认保存";
						UITools.paintYindao(g, Tools.getStrArray(string, W - 8), m_x + getYindaoX() + UITools.W_BAG + 5
								, m_y + getYindaoY() + UITools.H_BAG + 5, W, 1, UITools.W_BAG
										+ (UITools.IW_WIN << 1), UITools.H_BAG + (UITools.IW_WIN << 1));
						break;
					case GROUP_SET_BAG:
						UITools.paintYindao(g, Tools.getStrArray("单击设置快捷栏", W - 8), m_x + getYindaoX()
								+ UITools.W_BAG + 5
								, m_y + getYindaoY() + UITools.H_BAG + 5, W, 1, UITools.W_BAG
										+ (UITools.IW_WIN << 1), UITools.H_BAG + (UITools.IW_WIN << 1));
						break;
					default:
						break;
				}
				break;
		}
	}

	/*************************/
	// Set 从普通入口进入
	/*************************/

	private void paintSetShortcut(Graphics g)
	{
		// UITools.paintContentRect(g, m_x + X_SET_SHORTCUT_CONTENT, m_y + Y_SET_SHORTCUT_CONTENT,
		// W_SET_SHORTCUT_CONTENT,H_SET_SHORTCUT_CONTENT);
		int tempY = m_y + Y_SET_SHORTCUT;
		int index = 0;
		for (int i = 0; i < NUM_SET_SHORTCUT_ROW; i++) {
			int tempX = m_x + X_SET_SHORTCUT;
			for (int j = 0, length = NUM_SET_SHORTCUT_COL - 1; j < length; j++) {
				paintSetItem(g, tempX, tempY, m_set_shortcutItems[m_set_index_switch][j]);
				Tools.drawNumber(g, GameScene.s_img_num, tempX + UITools.W_BAG, tempY + UITools.H_BAG, UITools.W_NUM, UITools.H_NUM, j + 1, 0, Tools.RIGHT_BOTTOM, false);
				index++;
				tempX += RW_SET_SHORTCUT;
			}
			// 切换栏
//			Tools.drawNumber(g, GameScene.s_img_num, tempX, tempY, 5, 7, NUM_SET_SHORTCUT_COL, 0, Tools.LEFT_TOP,
//							false);
//			Tools.drawNumber(g, GameScene.s_img_num, tempX + UITools.W_BAG, tempY + UITools.H_BAG, UITools.W_NUM,
//					UITools.H_NUM, i + 1, 0, Graphics.BOTTOM|Graphics.RIGHT, false);
			
			paintSetSwitch(g, tempX, tempY);
			tempY += RH_SET_SHORTCUT;
		}
	}

	private void paintSetSwitch(Graphics g, int x, int y)
	{
		g.drawImage(UIManager.IMAGE_ITEM_OPEN, x, y, Graphics.TOP | Graphics.LEFT);

		if (m_set_index_switch == 0) {
			Tools.drawRegion(g, UIManager.IMAGE_ARR_DARK, x + 2, y + 2, Tools.TRANS_NONE, Tools.LEFT_TOP);
			Tools.drawRegion(g, UIManager.IMAGE_ARR_LIGHT, x + 2, y + 2 + UIManager.IMAGE_ARR_LIGHT.getHeight(),
					Tools.TRANS_HV, Tools.LEFT_TOP);
		}
		else {
			Tools.drawRegion(g, UIManager.IMAGE_ARR_LIGHT, x + 2, y + 2, Tools.TRANS_NONE, Tools.LEFT_TOP);
			Tools.drawRegion(g, UIManager.IMAGE_ARR_DARK, x + 2, y + 2 + UIManager.IMAGE_ARR_LIGHT.getHeight(),
					Tools.TRANS_HV, Tools.LEFT_TOP);
		}
//		Tools.drawNumber(g, GameScene.s_img_num, x, y, 5, 7, 9, 0, Graphics.TOP | Graphics.LEFT, false);
		
		Tools.drawNumber(g, GameScene.s_img_num, x + UITools.W_BAG, y + UITools.H_BAG, UITools.W_NUM,
				UITools.H_NUM, 9, 0, Graphics.BOTTOM|Graphics.RIGHT, false);
	}

	private void paintBagRect(Graphics g)
	{
		int tempX = m_x + X_SET_BAG_RECT;
		int tempY = m_y + Y_SET_BAG_RECT;
		UITools.paintContentRect(g, tempX, tempY, W_SET_BAG, H_SET_BAG);
		//
		int clipX = g.getClipX();
		int clipY = g.getClipY();
		int clipW = g.getClipWidth();
		int clipH = g.getClipHeight();
		int iw_sum = (IW_CONTENT << 1);
		g.setClip(tempX + IW_CONTENT, tempY + iw_sum - 2, W_SET_BAG - iw_sum + 1, H_SET_BAG - iw_sum + 1);
		paintLabels(g);
		paintSetItems(g);
		g.setClip(clipX, clipY, clipW, clipH);
	}

	private final void paintLabels(Graphics g)
	{
		int tempX = m_x + X_SET_LABEL;
		int tempY = m_y + Y_SET_LABEL;
		if (SIZE_SET_SKILL != 0) {
			UITools.paintLabelImage(g, tempX, tempY, W_SET_LABEL, H_SET_LABEL, UIManager.IMAGE_LABEL_SKILL, true);
			tempY += (H_SET_SKILL + H_SET_MID);
		}
		if (SIZE_SET_ACTORITEM != 0) {
			UITools.paintLabelImage(g, tempX, tempY + m_set_relY_label, W_SET_LABEL, H_SET_LABEL, UIManager.IMAGE_WUPIN, true);
			tempY += (H_SET_ITEM + H_SET_MID);
		}
		if (SIZE_SET_FUN != 0) {
			UITools.paintLabelImage(g, tempX, tempY + m_set_relY_label, W_SET_LABEL, H_SET_LABEL,
					UIManager.IMAGE_LABEL_FUNCATION, true);
		}
	}

	private void paintSetItems(Graphics g)
	{
		int tempY = m_y + Y_SET_BAG;
		int index = m_set_bag_top;
		int maxSize = m_set_bagItems.length;
		int skillSize = SIZE_SET_SKILL;
		for (int i = 0; i < NUM_SET_BAG_ROW; i++) {
			int tempX = m_x + X_SET_BAG;
			for (int j = 0; j < NUM_SET_BAG_COL; j++) {
				if (index >= maxSize) {
					paintSetItem(g, tempX, tempY, null);
				}
				else {
					paintSetItem(g, tempX, tempY, m_set_bagItems[index]);
				}
				index++;
				tempX += RW_SET_BAG;
			}
			tempY += RH_SET_BAG;
			// 中间行
			if (SIZE_SET_SKILL <= 0) {
				continue;
			}
			if (index == skillSize) {
				tempY += H_SET_MID;
			}
		}
	}

	/**
	 * 2012-3-5 下午01:11:48 venizeng
	 * @param g
	 */
	private void paintSetDrag(Graphics g)
	{
		UITools.paintScrollBar(g, m_x + UITools.X_DRAG, m_y + Y_SET_BAG, H_SET_BAG, m_set_plan);
	}

	/**
	 * 绘制一个格子内的数据 2012-3-5 上午10:02:48 venizeng
	 * @param g
	 * @param x
	 * @param y
	 * @param object
	 */
	private void paintSetItem(Graphics g, int x, int y, Object object)
	{
		g.drawImage(UIManager.IMAGE_ITEM_OPEN, x, y, 0);
		if (object == null) {
			return;
		}
		if (object instanceof RoleCombatSkill) {
			RoleCombatSkill skill = (RoleCombatSkill) object;
			skill.drawIcon(g, x + 1, y + 1, 0);
		}
		else if (object instanceof MenuFunction) {
			MenuFunction function = (MenuFunction) object;
			function.drawIcon(g, x + 1, y + 1);
		}
		else if (object instanceof ActorItem) {
			ActorItem item = (ActorItem) object;
			item.drawIcon(g, x + 1, y + 1, 0);
		}
	}

	private final int KEY_CONFIG = AbstractGameScreen.GK_KEY5;
	private final int KEY_DETAIL = AbstractGameScreen.GK_KEY0;
	private final int KEY_DELETE = AbstractGameScreen.GK_KEY3;
	private final int KEY_SWITCH = AbstractGameScreen.GK_KEY9;
//	private final String STR_SET_DESCRIBE1 = "修改快捷键";
	private final String STR_SET_DESCRIBE4 = "查看详情";
//	private final String STR_SET_DESCRIBE3 = "删除快捷 ";
	private final String STR_SET_DESCRIBE2 = "切换快捷栏";

	private void paintSetSkillDescribe(Graphics g)
	{

	}

	private void paintSetDescribe(Graphics g)
	{
		int tempX = m_x + X_SET_DESCRIBE;
		int tempY = m_y + Y_SET_DESCRIBE;
		// UITools.paintContentRect(g, tempX, tempY, W_SET_DESCRIBE, H_SET_DESCRIBE);
		tempX += UITools.IW_RECT_CONTENT;
		tempY += UITools.IH_RECT_CONTENT;
		
		tempX = m_x + (m_w >> 1);
		tempY = m_y + UITools.ENDY_CONTENT;
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_YESS));
//		g.drawString(STR_SET_DESCRIBE3, tempX-5, tempY, Tools.RIGHT_BOTTOM);
		g.drawString(STR_SET_DESCRIBE4, tempX+5, tempY, Tools.HCENTER_BOTTOM);
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
//		int strWidth3 = g.getFont().stringWidth(STR_SET_DESCRIBE3)+10;
		int strWidth4 = g.getFont().stringWidth(STR_SET_DESCRIBE4)+10;
//		g.drawRect(tempX-strWidth3-5, tempY-AbstractGameScreen.FONT_H, strWidth3, AbstractGameScreen.FONT_H);
		g.drawRect(tempX-(strWidth4>>1), tempY-AbstractGameScreen.FONT_H, strWidth4, AbstractGameScreen.FONT_H);
		
		tempY -= AbstractGameScreen.FONT_H+10;
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_YESS));
//		g.drawString(STR_SET_DESCRIBE1, tempX-5, tempY, Tools.RIGHT_BOTTOM);
		g.drawString(STR_SET_DESCRIBE2, tempX+5, tempY, Tools.HCENTER_BOTTOM);
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
//		int strWidth1 = g.getFont().stringWidth(STR_SET_DESCRIBE1)+10;
		int strWidth2 = g.getFont().stringWidth(STR_SET_DESCRIBE2)+10;
//		g.drawRect(tempX-strWidth1, tempY-AbstractGameScreen.FONT_H, strWidth1, AbstractGameScreen.FONT_H);
		g.drawRect(tempX-(strWidth2>>1), tempY-AbstractGameScreen.FONT_H, strWidth2, AbstractGameScreen.FONT_H);
	}

	private void paintSetFocus(Graphics g)
	{
		// 绘制快捷栏选中
		int tempX = m_x + X_SET_SHORTCUT + m_set_x_shortcut_fos;
		int tempY = m_y + Y_SET_SHORTCUT;
		switch (m_state) {
			case STATE_SET:
			case STATE_TEACH:
				switch (m_groupId) {
					case GROUP_SET_SHORTCUT:
						UITools.paintFocusBox(g, tempX, tempY, UITools.W_BAG, UITools.H_BAG);
						UITools.paintItemDescribe(g, tempX, tempY, m_w, m_h,
								m_set_shortcutItems[m_set_index_switch][m_set_index_shortcut]);
						break;
					case GROUP_SET_BAG:
					default:
						UITools.paintSelItem(g, tempX, tempY, UITools.W_BAG, UITools.H_BAG);
						tempX = m_x + X_SET_BAG + m_set_x_bag_fos;
						tempY = m_y + Y_SET_BAG + m_set_y_bag_fos;
						UITools.paintFocusBox(g, tempX, tempY, UITools.W_BAG, UITools.H_BAG);
						if (m_groupIndex + m_set_bag_top >= m_set_bagItems.length) {
							return;
						}
						UITools.paintItemDescribe(g, tempX, tempY, m_w, m_h, m_set_bagItems[m_groupIndex
								+ m_set_bag_top]);
						break;
				}
				break;

			default:
				break;
		}
	}
/////////////////////////////////
	int[][] mshotcutRect;
	int[][] mbagRect;
	protected void registerTouch() {
		clearAllRects();
		registerNormalSoft();
		int tempY = m_y + Y_SET_SHORTCUT;
		mshotcutRect = new int[NUM_SET_SHORTCUT_COL][];
		int tempX = m_x + X_SET_SHORTCUT;
		for (int j = 0;j < NUM_SET_SHORTCUT_COL; j++) {
			mshotcutRect[j] = new int[]{tempX, tempY,UITools.W_BAG, UITools.H_BAG};
			tempX += RW_SET_SHORTCUT;
		}
		initTouchRect(mshotcutRect);
		
		mbagRect = new int[NUM_SET_BAG_ROW*NUM_SET_BAG_COL][];
		tempY = m_y + Y_SET_BAG;
		for (int i = 0; i < NUM_SET_BAG_ROW; i++) {
			tempX = m_x + X_SET_BAG - (IW_SET_BAG>>1);
			for (int j = 0; j < NUM_SET_BAG_COL; j++) {
				mbagRect[i*NUM_SET_BAG_COL+j] = new int[]{tempX, tempY,RW_SET_BAG,RH_SET_BAG};
				tempX += RW_SET_BAG;
			}
			tempY += RH_SET_BAG;
		}
		initTouchRect(mbagRect);
		initTouchRect(new int[][]{
				{442,67,24,28},
				{442,200,24,28},
				//
				{170,230,69+69,16},
//				{240,230,69,16},
				{197,256,39+70,16},
//				{240,256,70,16},
		});
	}

	protected void onTouchRect(int[][] rect, int touchid) {
		if (rect == mshotcutRect) {
			if (m_groupId == GROUP_SET_SHORTCUT) {
				if (m_index == touchid) {
//					GameTouchManager.keyPressedFire();
					deleteSetShortcut();
				} else {
					setWindowIndex(touchid);
				}
			} else {
//				GameTouchManager.keyPressedRSoft();
//				keySetRightSoft();
				setWindowIndex(touchid);
			}
		} else if (rect == mbagRect) {
			if (m_groupId == GROUP_SET_SHORTCUT) {
//				clickSetShortcutItem();
				setWindowIndex(INDEX_SET_BAG_FIRST+touchid);
			} else {
//				if (m_index == touchid) {
//					GameTouchManager.keyPressedFire();
//				} else {
					setWindowIndex(INDEX_SET_BAG_FIRST+touchid);
//				}
			}
		} else {
			switch(touchid) {
			case 0:
				GameTouchManager.keyPressedDir(1);
				break;
			case 1:
				GameTouchManager.keyPressedDir(3);
				break;
//			case 2:
//				GameTouchManager.keyPressedFire();
//				break;
			case 2:
				GameTouchManager.keyPressedNum(9);
				break;
//			case 4:
//				GameTouchManager.keyPressedNum(3);
//				break;
			case 3:
				GameTouchManager.keyPressedNum(0);
				break;
			}
		}
	}

	
}
